package problems.daily;

/**
 * 1470. 重新排列数组
 * <p>https://leetcode.cn/problems/shuffle-the-array/</p>
 *
 * @author habitplus
 * @since 2022/8/29 09:17
 */
public class DT1470 {
    public int[] shuffle(int[] nums, int n) {
        if (nums == null || nums.length < 3 || n < 2) return nums;

        int[] aux = new int[n];
        int k;
        System.arraycopy(nums, n, aux, 0, n);

        for (int i = n - 1; i >= 0; --i) {
            k = 2 * i;
            nums[k] = nums[i];
            nums[k + 1] = aux[i];
        }

        return nums;
    }
}
